Caption = "While the file is loading, you will see the number of lines processed counting up. That count will start over for a 2nd pass, and the list boxes will load when the second pass is completed. Click on the sub or function that you want to view, and the variable list boxes will load with the data from the sub or function that you selected. You can run this program from outside of VB, unmaximize the form, tuck it over on the right side of your screen, load VB, and then have this program available on the right while you trim unneeded declarations from your subs and functions on the left."
Height = 1215
Left = 180
TabIndex = 19
Top = 3000
Width = 9135
End
Begin Label Label12
Caption = "The code, I know, is quite messy. No excuses, I wrote it in one draft, it has served my purpose, and I have no more time to spend on it. No guarantees, either, but the program only reads files. It won't write to any files. If you can tidy things up and find a bug and improve the interface and add features, please upload your version and tell everybody else. Thanks."
Height = 975
Left = 60
TabIndex = 18
Top = 5340
Width = 8115
End
Begin Label Label11
Caption = "I would also love to find a VB cross-reference tool that will locate globally-declared variables, and list the globally-declared variables that are only referenced in one module. That way, you would then be able to declare those variables at the module-level. I would ALSO love to have a tool that will allow you to take a sub or function, and list the module-declared variables used in that sub or function, and list the globally-declared variables used in that sub or function. Anybody know of a tool like that?"
Height = 1155
Left = 120
TabIndex = 16
Top = 4260
Width = 9135
End
Begin Label Label10
Caption = "When you write a large VB program, sometimes you wind up with locally-declared variables that are no longer being used in the subs and functions in which they reside. I haven't been able to find a utility that will locate those for me, EASILY, so I wrote this."
Height = 615
Left = 180
TabIndex = 15
Top = 540
Width = 9135
End
Begin Label Label9
Caption = "This program will take a VB module, a .FRM or a .BAS, and go through the module, locating the subs and functions. It will identify the locally-declared variables in the subs and functions, and will find the locally-declared variables that are NOT USED in the subs and functions in which they reside. That will allow you to delete the variable declaration line (after you CONFIRM that the variable isn't referenced in the sub or function by using the Find tool, of course). There are a few bugs in the program -- sometimes the variables listed aren't listed for the correct sub or function -- they're one sub off on the list, sometimes when reading a module, many lines are taken in on one input statement, and a line like ""Dim x, y as integer"" won't register the y as a variable. "
Height = 1575
Left = 180
TabIndex = 14
Top = 1260
Width = 9135
End
Begin Label Label8
Caption = "If you have comments, please contact me on CompuServe, 71630,1265."
Height = 615
Left = 3420
TabIndex = 13
Top = 60
Width = 3255
End
Begin Label Label7
Caption = "Programmed by Steve Denenberg"
Height = 315
Left = 180
TabIndex = 12
Top = 60
Width = 3075
End
End
Begin CommonDialog CMDialog1
Filter = "Modules and Forms|*.bas;*.frm|All files (*.*)|*.*"
InitDir = "c:\"
Left = 4680
Top = 3060
End
Begin ListBox listunusedvars
Height = 3345
Left = 60
TabIndex = 6
Top = 2520
Width = 2055
End
Begin ListBox listvariablenames
Height = 4905
Left = 2400
TabIndex = 3
Top = 960
Width = 1935
End
Begin CommandButton Command2
Caption = "End"
Height = 495
Left = 4500
TabIndex = 2
Top = 840
Width = 1215
End
Begin ListBox listsubname
Height = 1200
Left = 60
Sorted = -1 'True
TabIndex = 1
Top = 720
Width = 2055
End
Begin CommandButton Command1
Caption = "Load file"
Height = 495
Left = 4500
TabIndex = 0
Top = 240
Width = 1215
End
Begin Label Label6
Height = 315
Left = 60
TabIndex = 10
Top = 0
Width = 2115
End
Begin Label Label5
Caption = "Sub or Function name"
Height = 255
Left = 60
TabIndex = 9
Top = 420
Width = 2055
End
Begin Label Label4
Caption = "All variables"
Height = 255
Left = 2400
TabIndex = 8
Top = 600
Width = 1275
End
Begin Label Label3
Caption = "UNUSED variables"
Height = 255
Left = 60
TabIndex = 7
Top = 2220
Width = 1815
End
Begin Label Label2
Caption = "lines read:"
Height = 255
Left = 4800
TabIndex = 5
Top = 1500
Width = 975
End
Begin Label Label1
Caption = "0"
Height = 315
Left = 4800
TabIndex = 4
Top = 1740
Width = 1035
End
Begin Menu aboutitem
Caption = "About"
End
Option Explicit
Option Compare Text
Dim lineoftext(200) As String
Dim fileend As Integer
Dim filetoopen As String
Dim bodyindex As Integer
Dim variable(50, 200, 1) As String
'first parameter is the sub or function number
'second parameter lists the variables that are locally-declared
'if third parameter=0, the string is the name of the variable
'if third parameter=1, the string= "u" if the variable is used in
' the sub or function.
Dim doublequote As String * 1
Dim variableindex As Integer
Dim subnumber As Integer
Dim linesread As Integer
Dim z%
Dim cancelread As Integer
Sub aboutitem_Click ()
picture1.Left = 0
picture1.Top = 0
picture1.ZOrder
picture1.Visible = True
End Sub
Sub Command1_Click ()
Dim stringa As String
Dim cc As Integer
On Error GoTo errorhere
fileend = False
cancelread = False
Erase variable
listsubname.Clear
listunusedvars.Clear
listvariablenames.Clear
cmdialog1.Action = 1
filetoopen = cmdialog1.Filename
label6.Caption = filetoopen
label6.Refresh
loadlinesoftext
If cancelread Then
listsubname.Clear
listunusedvars.Clear
listvariablenames.Clear
Exit Sub
End If
On Error GoTo 0
For cc = 0 To subnumber - 1
listsubname.AddItem variable(cc, 0, 0)
Next cc
listsubname.Refresh
loadunusedvariables
getout:
Exit Sub
errorhere:
Resume getout
End Sub
Sub Command2_Click ()
End Sub
Sub Command3_Click ()
picture1.Visible = False
End Sub
Sub Command4_Click ()
cancelread = True
End Sub
Sub findunusedvariables (theline As String)
Dim cc As Integer
Dim saveit As String
Dim maxvariable As Integer
Dim firstcomma As Integer
Dim firstspace As Integer
Dim firstparen As Integer
Dim firstparenc As Integer
Dim firstperiod As Integer
ReDim varsthisline(1000) As String
Dim varsthislineindex As Integer
Dim dd As Integer
Dim ee As Integer
'find the highest index of variable(subnumber , ??, 0). That tells
' how many variables were found that were declared in subroutine #subnumber.
For cc = 1 To 200
If variable(subnumber, cc, 0) = "" Then
maxvariable = cc - 1
Exit For
End If
Next cc
saveit = theline
'a word ends at a space, at an open parenthesis, at a comma, at a close